package cn.javase.concurrent._并发编程._06_共享模型之无锁._原子整数;

import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerTest {
    public static void main(String[] args) {
        AtomicInteger i = new AtomicInteger(0);
        /* 简单运算 */
        System.out.println(i.incrementAndGet()); // ++i
        System.out.println(i.getAndIncrement()); // i++
        System.out.println(i.getAndAdd(5)); // 2, 12
        System.out.println(i.addAndGet(5)); // 12, 12
        /* 复杂一点的运算 */
        System.out.println(i.getAndUpdate(x -> x * 5));
        System.out.println(i.get());
    }
}
